<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <img src="img/01.jpg" alt="" width="300" />
    <div>
      <button>上一张</button>
      <button>下一张</button>
    </div>

    <script src="../../js/tools.js"></script>
    <script>
      var img = $("img");
      var previous = $("button:nth-of-type(1)");
      var next = $("button:nth-of-type(2)");
      var arrPic = [
        "img/01.jpg",
        "img/a.jpg",
        "img/03.jpg",
        "img/04.jpg",
        "img/05.jpg",
      ];

      var index = 0;

      previous.onclick = function () {
        index--;
        if (index < 0) {
          index = arrPic.length - 1;
        }
        img.src = arrPic[index];
      };

      next.onclick = function () {
        index++;
        if (index == arrPic.length) {
          index = 0;
        }
        img.src = arrPic[index];
      };
    </script>
  </body>
</html>
